//
//  HotBrandTableViewCell.m
//  19-CarHomeWork
//
//  Created by 曹曹 on 16/8/9.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "HotBrandTableViewCell.h"
#import "HotCollectionViewCell.h"
#import "CGXList.h"
#import "UIImageView+DownloadImage.h"

@interface HotBrandTableViewCell () <UICollectionViewDelegate, UICollectionViewDataSource>

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *layout;

@end

@implementation HotBrandTableViewCell

- (void)layoutSubviews {
    [super layoutSubviews];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.contentSize = CGSizeMake(self.contentView.frame.size.width, self.contentView.frame.size.height);
    _collectionView.backgroundColor = [UIColor whiteColor];
    _layout.itemSize = CGSizeMake((self.contentView.frame.size.width - 60) / 5, (CGRectGetHeight(self.bounds) - 30) / 2);
    _layout.minimumInteritemSpacing = 10;
    _layout.minimumLineSpacing = 10;
    _layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    if (_list) {
        [self.collectionView reloadData];
    }
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _list.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HotCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"hot" forIndexPath:indexPath];
    cell.label.text = _list[indexPath.row].name;
    [cell.imageView asyncDownloadImageWithURL:_list[indexPath.row].img completionHandler:^(NSData *data, UIImage *image) {
    }];
    return cell;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
